<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="static/css/basic.css">
        <link rel="stylesheet" href="static/css/login.css">
        <script type="text/javascript" src="static/js/jQuery.js"></script>
        <script type="text/javascript" src="static/js/basic.js"></script>
        <script type="text/javascript" src="static/layer-v3.1.1/layer/layer.js"></script>
        <title>简学应用平台</title>
    </head>
    <body>
    	<div class="pagewrap">
            <div class="website-modify">&nbsp;</div>
    		<div class="main" id="screen">
    			<div class="login-page jkgl-login">
    				<div class="bottom-bg">
                         <img src="static/images/jkgl_login/bottom_bg.png" >  <div class="foot-record">
                                Copyright © 2019  烟台卓讯数据科技有限公司 版权所有
                            </div>         
                    </div>
                    <div class="yun-img">
                        <div class="yun-list">
                            <div class="yun">
                                <i class="ico ico-yun1"></i>
                                <i class="ico ico-yun2"></i>
                                <i class="ico ico-yun3"></i>
                                <i class="ico ico-yun4"></i>
                                <i class="ico ico-yun5"></i>
                                <!-- <i class="ico ico-yun6"></i> -->
                            </div>
                            <div class="yun">
                                <!-- <i class="ico ico-yun1"></i> -->
                                <i class="ico ico-yun2"></i>
                                <i class="ico ico-yun3"></i>
                                <i class="ico ico-yun4"></i>
                                <i class="ico ico-yun5"></i>
                                <i class="ico ico-yun6"></i>
                            </div>
                        </div>
                    </div>
    				<div class="login-block">
    					<div class="login-pop">
    						<h3 class="platform-name">
    							<i class="ico ico-logo"></i>
    							简学应用平台
    						</h3>
    						<div class="login-body clearfix">
    							<div class="login-info">
                                    
    								<div class="form-list">
                                        <div class="li">
                                            <div class="ele-wrap" style="font-size: 16px;">
                                                <strong>用户类型：</strong>
                                                <input checked class="radio" type="radio" name="t1" id="t1" value="0" />
                                                <label for="t1">管理员</label>
                                                &nbsp;&nbsp;&nbsp;
                                                <input class="radio" type="radio" name="t1" id="t2" value="1" />
                                                <label for="t2">教师</label>
                                            </div>
                                        </div>
    									<div class="li">
    										<div class="ele-wrap">
                                                <i class="ico ico-user"></i>
    											<input type="text" class="form-control user" id="username" placeholder="用户名">
    										</div>
    									</div>
    									<div class="li">
    										<div class="ele-wrap">
                                                <i class="ico ico-password"></i>
    											<input type="password" class="form-control password" id="password" placeholder="密码">
    										</div>
    									</div>
                                        <div class="li">
                                            <div class="ele-wrap">
                          <!--                       <div class="code-img">
                                                    <img src="static/images/code.png">
                                                </div> -->
                                                <div style="" id="kaptchaShow" class="code-img">
								   					<img src="kaptcha.jpg" id="kaptchaImage" onclick="changeCode()"/>       
												</div>
                                                <div class="proving-code">
                                                    <i class="ico ico-code"></i>
                                                    <input type="text" class="form-control code" id="kaptcha" placeholder="验证码">
                                                </div>
                                            </div>
                                        </div>
    									<div class="li">
    										<div class="ele-wrap">
    											<div class="proxyinput-group">
							                        <label class="proxyinput proxy-checkbox">
							                            <span class="h0hidden"><input type="checkbox" name="checkbox1" checked="checked" id="checkbox"></span>记住密码
                                                    </label>
                                                </div>
                                                <p style="margin-top: -20px; text-align: right; font-size: 18px; text-decoration: underline;cursor:pointer;" onclick="addUpdateUser()">新用户注册</p>
    										</div>
    									</div>
    									<div class="li">
    										<div class="ele-wrap">
                                                <a class="btn btn-blue" href="javascript:void(0);" onclick="login()">登 录</a> 
                                            </div>
    									</div>
    								</div>
    							</div>
    							<div class="login-right">
    								<div class="login-ewm">
    									<div class="ewm-img">
    										<img src="static/images/login_ewm.png">
    									</div>
    									<span class="ewm-txt">扫一扫下载简学手机APP</span>
    								</div>
    							</div>
    						</div>
    					</div>
    				</div>
    			</div>
    		</div>
    	</div>
    </body>
</html>
<script>
	$(function () {
		// 获取焦点
		$('.login-info .li .form-control').on('focus', function () {
			$(this).closest('.li').addClass('focus');
			$(this).closest('.li').siblings().removeClass('focus');
		});
		$('.login-info .li .form-control').on('blur', function () {
			$(this).closest('.li').removeClass('focus');
		}); 
		// 左右高度计算
		var infoH = $('.login-info').outerHeight();
		$('.login-right').height(infoH+'px');
        // 徽章
        $('.badge-cell .ico-badge').hover(function () {
            var badgConH =$('.login-body').outerHeight() - 25;
            $('.badg-con, .badg-details').css('height',badgConH+'px');
            var index = $(this).index();
            var icoBadg = $(this).closest('.ico-badge');
            var arrowLeft = $('.badge-cell .ico-badge:eq('+index+')').position().left + $('.badge-cell .ico-badge:eq('+index+')').width()/2 + 5;
            $(this).closest('.badge-bloak').find('.badg-con .ico-arrow').css('left', arrowLeft+'px');
            icoBadg.find('.badg-con').show();
            icoBadg.siblings().find('.badg-con').hide();
        }, function () {
            $('.badg-con').hide();
        });
        
        
        
        
        
    });
    function login(){
   	 var userName = document.getElementById("username").value;  
		    if(userName == ''){  
		        alert("请输入用户名。");  
		        return;  
		    }  
	    var userPass = document.getElementById("password").value;  
		    if(userPass == ''){  
		        alert("请输入密码。");  
		        return;  
		    }  
	    var kaptcha = document.getElementById("kaptcha").value;  
		    if(kaptcha == ''){  
		        alert("请输入验证码。");  
		        return;  
		    }  
    
     var objChk = document.getElementById("checkbox");  
		    if(objChk.checked){  
		        //添加cookie  
		        addCookie("userName",userName,7,"/");  
		        addCookie("userPass",userPass,7,"/");  
		        addCookie("userTypeValue",$('.radio[name="t1"]:checked').val(),7,"/");  
		    }else{  
		        deleteCookie("userName","/");
		        deleteCookie("userPass","/");
		        deleteCookie("userTypeValue","/");
		      
		    } 
    
	    $.ajax({
				type : "post",
				url : "./userlogin.do",
				data : {
					"username" : $("#username").val(),
					"password" : $("#password").val(),
					"kaptcha"  : $("#kaptcha").val(),
					"type":$('.radio[name="t1"]:checked').val()
				},
				dataType : "json",
				async : false,
				success : function(data) {
				//alert(JSON.stringify(data));
					if ("ok"==data[0].tishi) {
						window.location.href = "main.html";
					} else if ("no"==data[0].tishi) {
						alert("请检查账号、密码是否正确！");
						$("#kaptcha").val("");
						changeCode();
					}else if ("kaptcha"==data[0].tishi) {
						alert(data[0].msg);
						$("#kaptcha").val("");
						changeCode();
					}else if ("error"==data[0].tishi) {
						alert(data[0].msg);
					}else if("pastTime"==data[0].tishi){
						alert("试用期已过！");
					}
				}
			});
	    
	    
    }
    $(window).keydown(function(event) {  //键盘敲击事件
			if (event.keyCode == 13) {
				login();
			}
		});
		
function addUpdateUser() {
	layer.open({
		type : 2,
		area : [ '840px', '600px' ],
	    scrollbar: false,
	    shadeClose: true,
		fix : false, //不固定
		title : '用户注册',
		//maxmin : true,  
		skin: 'layui-layer-rim', //加上边框
   	    btn: ['保存 ', '关闭'],
		content : ["user-add.html",'no'],
		yes: function(index,layer){
                var iframeWin = parent.window[layer.find('iframe')[0]['name']];
                 iframeWin.save();
         },
		cancel : function(index) {
		}
		
	});
}
function changeCode() {  //刷新
    $('#kaptchaImage').hide().attr('src', 'kaptcha.jpg?' + Math.floor(Math.random()*100) ).fadeIn();  
    event.cancelBubble=true;  
}  

function addCookie(name,value,days,path){   /**添加设置cookie**/  
    var name = escape(name);  
    var value = escape(value);  
    var expires = new Date();  
    expires.setTime(expires.getTime() + days * 3600000 * 24);  
    //path=/，表示cookie能在整个网站下使用，path=/temp，表示cookie只能在temp目录下使用  
    path = path == "" ? "" : ";path=" + path;  
    //GMT(Greenwich Mean Time)是格林尼治平时，现在的标准时间，协调世界时是UTC  
    //参数days只能是数字型  
    var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();  
    document.cookie = name + "=" + value + _expires + path;  
}  
function getCookieValue(name){  /**获取cookie的值，根据cookie的键获取值**/  
    //用处理字符串的方式查找到key对应value  
    var name = escape(name);  
    //读cookie属性，这将返回文档的所有cookie  
    var allcookies = document.cookie;         
    //查找名为name的cookie的开始位置  
    name += "=";  
    var pos = allcookies.indexOf(name);      
    //如果找到了具有该名字的cookie，那么提取并使用它的值  
    if (pos != -1){                                             //如果pos值为-1则说明搜索"version="失败  
        var start = pos + name.length;                  //cookie值开始的位置  
        var end = allcookies.indexOf(";",start);        //从cookie值开始的位置起搜索第一个";"的位置,即cookie值结尾的位置  
        if (end == -1) end = allcookies.length;        //如果end值为-1说明cookie列表里只有一个cookie  
        var value = allcookies.substring(start,end); //提取cookie的值  
        return (value);                           //对它解码        
    }else{  //搜索失败，返回空字符串  
        return "";  
    }  
}  
function deleteCookie(name,path){   /**根据cookie的键，删除cookie，其实就是设置其失效**/  
    var name = escape(name);  
    var expires = new Date(0);  
    path = path == "" ? "" : ";path=" + path;  
    document.cookie = name + "="+ ";expires=" + expires.toUTCString() + path;  
}  
  
/**实现功能，保存用户的登录信息到cookie中。当登录页面被打开时，就查询cookie**/  
window.onload = function(){  

    var userNameValue = getCookieValue("userName");  
    document.getElementById("username").value = userNameValue;  

    var userPassValue = getCookieValue("userPass");  
    document.getElementById("password").value = userPassValue; 
    
     var userTypeValue = getCookieValue("userTypeValue");  
     if(userTypeValue=='0'){
     	$("#t1").attr("checked","checked");
     }else if(userTypeValue=='1'){
     	$("#t2").attr("checked","checked");
     }
    
    //alert(userNameValue) ;
   if(userPassValue!=""&&userPassValue!="")
   {
    $("#checkbox").attr("checked","checked");
    }
  //$("#chkRememberPass").attr("checked",false);
    

  

} 
</script>